//
//  MEnjoyViewController.m
//  NeusoftHBSJSober
//
//  Created by Apple-21 on 15/11/10.
//  Copyright (c) 2015年 com.neusoftsober. All rights reserved.
//

#import "MEnjoyViewController.h"
#import "MVIPCardService.h"
#import "VIPCardUseModel.h"
@interface MEnjoyViewController ()<UITableViewDataSource, UITableViewDelegate>
- (IBAction)backAction:(UIButton *)sender;
@property (weak, nonatomic) IBOutlet UILabel *noticeLabel;
@property (weak, nonatomic) IBOutlet UILabel *salemenNameLabel;
@property (weak, nonatomic) IBOutlet UILabel *salemenAddressLabel;
@property (weak, nonatomic) IBOutlet UILabel *salemenPhoneLabel;
@property (weak, nonatomic) IBOutlet UILabel *hasReturnCashLabel;
@property (weak, nonatomic) IBOutlet UILabel *returnCashLabel;
@property (weak, nonatomic) IBOutlet UILabel *pickupReturnLabel;
@property (weak, nonatomic) IBOutlet UILabel *returnPercentStringLabel;
@property (weak, nonatomic) IBOutlet UITableView *myTableView;

@property (nonatomic, strong) NSMutableArray *vipCardUseMutArray;
@end

@implementation MEnjoyViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
}
- (void)viewWillAppear:(BOOL)animated {

    if (self.myVipCardModel) {
        self.salemenNameLabel.text = self.myVipCardModel.salemanName;
        self.salemenAddressLabel.text = self.myVipCardModel.salemanAddress;
        self.salemenPhoneLabel.text = self.myVipCardModel.salemanPhone;
        self.hasReturnCashLabel.text = [NSString stringWithFormat:@"%@元",self.myVipCardModel.hasReturnCash];
        self.returnCashLabel.text = self.myVipCardModel.returnCash;
        self.pickupReturnLabel.text = [NSString stringWithFormat:@"%@元",self.myVipCardModel.pickUpCash];
        self.returnPercentStringLabel.text = [NSString stringWithFormat:@"%@折",self.myVipCardModel.returnPercentString];
        
        [self getVipCardUseSatuation];
    }
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    
}
- (IBAction)backAction:(UIButton *)sender {
    [self dismissViewControllerAnimated:YES completion:nil];
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {

    return 50.0;
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {

    UIView *headerView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, SCREENWIDTH, 50.0)];
    headerView.backgroundColor = [UIColor whiteColor];
    UILabel *titleLabel = [[UILabel alloc]initWithFrame:CGRectMake(10, 0, SCREENWIDTH, 23)];
    titleLabel.text = @"VIP会员卡共用情况";
    titleLabel.font = [UIFont fontWithName:nil size:14.0];
    titleLabel.textAlignment = NSTextAlignmentLeft;
    [headerView addSubview:titleLabel];
    
    UIView *titleView = [[UIView alloc]initWithFrame:CGRectMake(0, 23, SCREENWIDTH, 27)];
    titleView.backgroundColor = WHITESMOLKE;
    
    UILabel *accountLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, SCREENWIDTH/4, 27)];
    accountLabel.text = @"账号";
    accountLabel.textAlignment = NSTextAlignmentCenter;
    accountLabel.font = [UIFont fontWithName:nil size:13.0];
    accountLabel.textColor = [UIColor blackColor];
    [titleView addSubview:accountLabel];

    UILabel *IDLabel = [[UILabel alloc]initWithFrame:CGRectMake(SCREENWIDTH/4, 0, SCREENWIDTH/4-20, 27)];
    IDLabel.text = @"ID号";
    IDLabel.textAlignment = NSTextAlignmentCenter;
    IDLabel.textColor = [UIColor blackColor];
    IDLabel.font = [UIFont fontWithName:nil size:13.0];
    [titleView addSubview:IDLabel];
    
    UILabel *timeLabel = [[UILabel alloc]initWithFrame:CGRectMake(SCREENWIDTH/4*2-20, 0, SCREENWIDTH/4+40, 27)];
    timeLabel.text = @"日期";
    timeLabel.textAlignment = NSTextAlignmentCenter;
    timeLabel.font = [UIFont fontWithName:nil size:13.0];
    timeLabel.textColor = [UIColor blackColor];
    [titleView addSubview:timeLabel];
    
    UILabel *enjoyLabel = [[UILabel alloc]initWithFrame:CGRectMake(SCREENWIDTH/4*3+20, 0, SCREENWIDTH/4-20, 27)];
    enjoyLabel.text = @"是否共用";
    enjoyLabel.textAlignment = NSTextAlignmentCenter;
    enjoyLabel.font = [UIFont fontWithName:nil size:13.0];
    [titleView addSubview:enjoyLabel];
    [headerView addSubview:titleView];
    return headerView;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {

    return self.vipCardUseMutArray.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    static NSString *cellStr = @"CELL_IND";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellStr];
    if (!cell) {
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellStr];
        UILabel *accountLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, SCREENWIDTH/4, 30)];
        accountLabel.textAlignment = NSTextAlignmentCenter;
        accountLabel.font = [UIFont fontWithName:nil size:12.0];
        accountLabel.tag = 101;
    
        [cell.contentView addSubview:accountLabel];
        
        UILabel *idLabel = [[UILabel alloc]initWithFrame:CGRectMake(SCREENWIDTH/4, 0, SCREENWIDTH/4-20, 30)];
        idLabel.textAlignment = NSTextAlignmentCenter;
        idLabel.font = [UIFont fontWithName:nil size:12.0];
        idLabel.tag = 102;
        [cell.contentView addSubview:idLabel];
        
        UILabel *timeLabel = [[UILabel alloc]initWithFrame:CGRectMake(SCREENWIDTH/4*2-20, 0, SCREENWIDTH/4+50, 30)];
        timeLabel.textAlignment = NSTextAlignmentCenter;
        timeLabel.font = [UIFont fontWithName:nil size:12.0];
        timeLabel.tag = 103;
        [cell.contentView addSubview:timeLabel];
        
        UIImageView *myImageView = [[UIImageView alloc]initWithFrame:CGRectMake(SCREENWIDTH/4*3+40, 5, 20, 20)];
        myImageView.backgroundColor = [UIColor whiteColor];
        myImageView.tag = 104;
        [cell.contentView addSubview:myImageView];
    }
    VIPCardUseModel *model = [[VIPCardUseModel alloc]init];
    model = [self.vipCardUseMutArray objectAtIndex:indexPath.row];
    ((UILabel *)[cell.contentView viewWithTag:101]).text = model.userName;
    ((UILabel *)[cell.contentView viewWithTag:102]).text = model.userID;
    NSString *string1 = [model.createTime substringToIndex:10];
    NSString *string2 = [model.createTime substringFromIndex:10];
    ((UILabel *)[cell.contentView viewWithTag:103]).text = [NSString stringWithFormat:@"%@ %@",string1,string2];
    if ([model.isUse integerValue]) {
        ((UIImageView *)[cell.contentView viewWithTag:104]).image = [UIImage imageNamed:@"isUseSelected@2x"];
    }
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    return cell;
}
- (void)getVipCardUseSatuation {

    [[MVIPCardService sharedClient]getVipCardUseSatuationWithCardID:[self.myVipCardModel.ID integerValue] completion:^(NSMutableArray *result){
    
        self.vipCardUseMutArray = [NSMutableArray arrayWithArray:result];
        [self.myTableView reloadData];
    } failure:^(NSString *error){
    
        
    }];
}
@end
